package com.itheima.controller;

import com.aliyun.heima.AliyunOSSOperator;
import com.itheima.anno.Log;
import com.itheima.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


@Slf4j
@RestController
public class UploadController {
    @Autowired
    private AliyunOSSOperator aliyunOSSOperator;

    // 上传文件到云
    @Log
    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws Exception {

        log.info("上传文件：{}",file);
        String url = aliyunOSSOperator.upload(file.getBytes(), file.getOriginalFilename());
        log.info("文件上传到oss的访问url:{}",url);

        return Result.success(url);
    }

}